encode_decode_content = """
>>> a = 'Hello python'
>>> print(f'original string is : {a}')
original string is : Hello python
>>> encode_bytes = a.encode('utf-8')
>>> print(f'encode bytes is : {encode_bytes}')
encode bytes is : b'Hello python'
>>> decode_correct = encode_bytes.decode('utf-8')
>>> print(f'decode bytes is : {decode_correct}')
decode bytes is : Hello python
"""

create_string_content = """
>>> a = "create"
>>> a += " a string"
>>> a
'create a string'
>>> b = "test " + a
>>> b
'test create a string'
"""

retrieve_string_content = """
>>> a
'create a string'
>>> a[3]
'a'
>>> a.index("a")
3
>>> a.find("r")
1
>>> a.startswith("cr")
True
>>> a.startswith("zr")
False
>>> a.endswith("te")
False
>>> a.endswith("ing")
True
"""

update_string_content = """
>>> a
'create a string'
>>> a.replace("create", "delete")
'delete a string'
>>> a.replace("a", "b")
'crebte b string'
>>> a.split(" ")
['create', 'a', 'string']
>>> ", ".join(a)
'c, r, e, a, t, e,  , a,  , s, t, r, i, n, g'
"""

delete_string_content = """
>>> a = "    hello world    "
>>> a.strip()
'hello world'
>>> a.lstrip()
'hello world    '
>>> a.rstrip()
'    hello world'
"""

format_string_content = """
print("hello %s" % "world")
print("hello {0} and {1}.".format("world","Python"))
# after python 3.6 f-strings
language = 'Python'
print(f'hello {language}')
"""

practice_content = {"encode_decode": encode_decode_content,
                    "create_string": create_string_content,
                    "retrieve_string": retrieve_string_content,
                    "update_string": update_string_content,
                    "delete_string": delete_string_content,
                    "format_string": format_string_content}


def write_content_to_file():
    practice_file = open("practice.txt", "a+")
    for key, val in practice_content.items():
        practice_file.write(f'{key} = \"\"\" {val}\"\"\"\n')
    practice_file.close()


def check_file_content():
    file_name = "practice.txt"
    try:
        with open(file_name, 'r') as f:
            file_content = f.read()
            print(file_content)
            print("check done")
    except FileNotFoundError as e:
        print(f'{e}')


if __name__ == '__main__':
    write_content_to_file()
    check_file_content()